package com.xbts.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.xbts.system.domain.CnHomeProductType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xbts.common.annotation.Log;
import com.xbts.common.core.controller.BaseController;
import com.xbts.common.core.domain.AjaxResult;
import com.xbts.common.enums.BusinessType;
import com.xbts.system.domain.CnHomeProduct;
import com.xbts.system.service.ICnHomeProductService;
import com.xbts.common.utils.poi.ExcelUtil;
import com.xbts.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * 首页产品信息Controller
 * @author xbts
 * @date 2023-11-30
 */
@Api("首页产品信息")
@RestController
@RequestMapping("/system/home/product")
public class CnHomeProductController extends BaseController {

    @Autowired
    private ICnHomeProductService cnHomeProductService;

    /**
     * 查询首页产品信息列表
     */
    @ApiOperation("查询首页产品信息列表")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody CnHomeProduct cnHomeProduct) {
        startPage(cnHomeProduct);
        List<CnHomeProduct> list = cnHomeProductService.selectCnHomeProductList(cnHomeProduct);
        return getDataTable(list);
    }
    /**
     * 用户端查询首页产品信息列表
     */
    @ApiOperation("用户端查询首页产品信息列表")
    @GetMapping("/user/list")
    public AjaxResult userList(String typeId) {
        return success(cnHomeProductService.listByUser(typeId));
    }

    /**
     * 查询首页产品信息列表(级联)
     */
    @ApiOperation("查询首页产品信息列表(级联)")
    @PreAuthorize("@ss.hasPermi('system:product:list')")
    @GetMapping("/allList")
    public AjaxResult allList() {
        List<CnHomeProductType> list = cnHomeProductService.allList();
        return success(list);
    }

    /**
     * 导出首页产品信息列表
     */
    @ApiOperation("导出首页产品信息列表")
    @PreAuthorize("@ss.hasPermi('system:product:export')")
    @Log(title = "首页产品信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,@RequestBody CnHomeProduct cnHomeProduct) {
        List<CnHomeProduct> list = cnHomeProductService.selectCnHomeProductList(cnHomeProduct);
        ExcelUtil<CnHomeProduct> util = new ExcelUtil<CnHomeProduct>(CnHomeProduct.class);
        util.exportExcel(response, list, "首页产品信息数据");
    }

    /**
     * 获取首页产品信息详细信息
     */
    @ApiOperation("获取首页产品信息详细信息")
    @ApiImplicitParam(name = "id", value = "首页产品信息ID", required = true, dataType = "String", paramType = "path", dataTypeClass=String.class)
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(cnHomeProductService.selectCnHomeProductById(id));
    }

    /**
     * 新增首页产品信息
     */
    @ApiOperation("新增首页产品信息")
    @PreAuthorize("@ss.hasPermi('system:product:add')")
    @Log(title = "首页产品信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody CnHomeProduct cnHomeProduct) {
        return toAjax(cnHomeProductService.insertCnHomeProduct(cnHomeProduct));
    }

    /**
     * 修改首页产品信息
     */
    @ApiOperation("修改首页产品信息")
    @PreAuthorize("@ss.hasPermi('system:product:edit')")
    @Log(title = "首页产品信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody CnHomeProduct cnHomeProduct) {
        return toAjax(cnHomeProductService.updateCnHomeProduct(cnHomeProduct));
    }

    /**
     * 删除首页产品信息
     */
    @ApiOperation("删除首页产品信息")
    @ApiImplicitParam(name = "ids", value = "首页产品信息ID集合", required = true, dataType = "String", paramType = "path", dataTypeClass=String.class)
    @PreAuthorize("@ss.hasPermi('system:product:remove')")
    @Log(title = "首页产品信息", businessType = BusinessType.DELETE)
	@PostMapping("/batchDelete")
    public AjaxResult batchDelete(@RequestBody List<String> ids) {
        return toAjax(cnHomeProductService.deleteCnHomeProductByIds(ids));
    }
}
